/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generadordescktop;

import generadorabm.Controladora;
import generadorabm.OTablaAtributos;
import generadorcommun.Atributo;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author agustin
 */
public class AtributosTableModel extends AbstractTableModel implements OTablaAtributos {

    public Object[][] cargarDatos() {

        try {
            List<Atributo> atributos2 = Controladora.getInstance().getCreadoraClase().getAtributos();
            atributos = new Atributo[atributos2.size()][1];

            for (int x = 0; x < atributos2.size(); x++) {
                atributos[x][0] = atributos2.get(x);
                System.out.println( atributos2.get(x).toString());
            }
        } catch (Exception e) {
            throw new UnsupportedOperationException(e.toString());
        }

        return atributos;
    }
    private Object atributos[][] = cargarDatos();

    public Object[][] getAtributos() {
        return atributos;
    }

    public void setAtributos(Object[][] atributos) {
        this.atributos = atributos;
    }

    public int getRowCount() {
        if (atributos.length == 0) {
            return 0;
        } else {
            return atributos.length;
        }

    }

    public int getColumnCount() {
        if (atributos.length == 0) {
            return 0;
        } else {
            return atributos[0].length;
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
       Atributo a = new Atributo();
        try {
            a = (Atributo) getAtributos()[rowIndex][columnIndex];

        } catch (Exception e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        return a;
    }

    public void notificarAtributo() {
//        atributos = cargarDatos();
        try {
            GeneradorDescktop.getInstance().actualizarAtributo();
        } catch (Exception e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

    }
}
